package com.ayuku.course.ui.student;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;

import com.ayuku.commons.AyukuDB;
import com.ayuku.commons.ui.BasicFormMaster;
import com.ayuku.course.persistence.model.Student;

public class FormStudent extends BasicFormMaster {
	private CompStudent cmp;
	private String custNo;
	private String alamat;
	private String nama;
	private Student pjo;

	public FormStudent(final Shell parent, final int style, final int mode) {
		super(parent, style, mode);
	}

	public void getPanelContent(final Group grpData) {
		cmp = new CompStudent(grpData, SWT.NONE);
	}

	@Override
	public void additionalProses() {
	
	}

	@Override
	public void clearContols() {
		/*cmp.getfNoInduk().setText("");
		cmp.getTxNama().setText("");

		cmp.getfEmail().setText("");
		cmp.getfPhone().setText("");*/

	}

	@Override
	protected void doLoadAdd(String key) {
		// TODO Auto-generated method stub

	}

	@Override
	public void doLoad(String key) throws Exception {

		pjo = (Student) AyukuDB.getPersist().readByPrimaryKey(Student.class,
				new Object[] { key });
/*
		cmp.getfNoInduk().setText(Util.nullToString(pjo.getCode()));
		cmp.getTxNama().setText(Util.nullToString(pjo.getFullName()));

		if ("L".equalsIgnoreCase(pjo.getGender())){
			cmp.getfLaki().setSelection(true);
			cmp.getfPerempuan().setSelection(false);
		}else{
			cmp.getfLaki().setSelection(false);
			cmp.getfPerempuan().setSelection(true);
		}
		
		cmp.getfTglLahir().setSelection(pjo.getBirthDate());
		cmp.getfBirthPlace().setText(Util.nullToString(pjo.getBirthPlace()));
		cmp.getfAddress().setText(Util.nullToString(pjo.getAddress()));
		
		cmp.getfParent().setText(Util.nullToString(pjo.getFatherMother()));
		cmp.getCmbPendidikan().setText(Util.nullToString(pjo.getEducation()));*/
		/*
		cmp.getfEmail().setText(Util.nullToString(pjo.getEmail()));
		cmp.getfPhone().setText(Util.nullToString(pjo.getPhone()));
        cmp.getfParentJob().setText(Util.nullToString(pjo.getParentJob()));
        cmp.getfParentPhone().setText(Util.nullToString(pjo.getParentPhone()));
        cmp.getfOperator().setText(Util.nullToString(pjo.getOperator()));
        
        cmp.getfTanggalDaftar().setSelection(pjo.getRegDate());
        cmp.getCmbLevel().setText(Util.nullToString(pjo.getCourseLevel()));
        
        cmp.getCmbSession().setText(Util.nullToString(pjo.getSession1()));
        
        cmp.getfBiayaDaftar().setValue(pjo.getRegistrationFee());
        cmp.getfBiayaBulanan().setValue(pjo.getMonthlyFee());
        cmp.getCmbPeriode().setText(Util.nullToString(pjo.getPeriode()));
        cmp.getfTanggalPeriode().setText(Util.nullToString(pjo.getPeriodeDate()));
        cmp.getfSenin().setSelection(pjo.getMonday());
        cmp.getfSelasa().setSelection(pjo.getTuesday());
        cmp.getfRabu().setSelection(pjo.getWednesday());
        cmp.getfKamis().setSelection(pjo.getTrusday());
        cmp.getfJumat().setSelection(pjo.getFriday());
        cmp.getfSabtu().setSelection(pjo.getSaturday());
        cmp.getfMinggu().setSelection(pjo.getSunday());
        cmp.getfStartCourse().setSelection(pjo.getStartDate());*/
	}

	@Override
	public boolean doValidate() {
	/*	custNo = cmp.getfNoInduk().getText();
		if (Util.isEmpty(custNo)) {
			Util.showMsgBox("Id harus dilengkapi!", 1, getDialogShell());
			cmp.getfNoInduk().setFocus();
			return false;
		}

		nama = cmp.getTxNama().getText();
		if (Util.isEmpty(nama)) {
			Util.showMsgBox("nama harus dilengkapi!", 1, getDialogShell());
			cmp.getTxNama().setFocus();
			return false;
		}
*/
		return true;
	}

	@Override
	public void enabledControl(final boolean otherField, final boolean keyField) {
	/*	cmp.getfNoInduk().setEditable(keyField);
		cmp.getTxNama().setEditable(otherField);
		cmp.getfTglLahir().setEditable(otherField);
		cmp.getfEmail().setEditable(otherField);
		cmp.getfPhone().setEditable(otherField);
		
		
		cmp.getfBirthPlace().setEditable(otherField);
		cmp.getfAddress().setEditable(otherField);
		
		cmp.getfParent().setEditable(otherField);
		cmp.getCmbPendidikan().setEditable(otherField);
		
		cmp.getfEmail().setEditable(otherField);
		cmp.getfPhone().setEditable(otherField);
        cmp.getfParentJob().setEditable(otherField);
        cmp.getfParentPhone().setEditable(otherField);
        cmp.getfOperator().setEditable(otherField);
        
        cmp.getfTanggalDaftar().setEditable(otherField);
        cmp.getCmbLevel().setEditable(otherField);
        
        cmp.getCmbSession().setEditable(otherField);
        
        cmp.getfBiayaDaftar().setEnabled(otherField);
        cmp.getfBiayaBulanan().setEnabled(otherField);
        cmp.getCmbPeriode().setEnabled(otherField);
        cmp.getfTanggalPeriode().setEditable(otherField);
        cmp.getfSenin().setEnabled(otherField);
        cmp.getfSelasa().setEnabled(otherField);
        cmp.getfRabu().setEnabled(otherField);
        cmp.getfKamis().setEnabled(otherField);
        cmp.getfJumat().setEnabled(otherField);
        cmp.getfSabtu().setEnabled(otherField);
        cmp.getfMinggu().setEnabled(otherField);
        cmp.getfStartCourse().setEditable(otherField);
        cmp.getCmbPendidikan().setEnabled(otherField);
        cmp.getCmbLevel().setEnabled(otherField);
        cmp.getCmbSession().setEnabled(otherField);*/
	}

	@Override
	public int doMainInsert() throws Exception {
		pjo = new Student();
		setPojoWithData();
		return 0; //StudentsImpl.add(pjo);
	}

	@Override
	public int doMainDelete() throws Exception {
		return 0; // StudentsImpl.delete(pjo.getCode());
	}

	@Override
	public int doMainUpdate() throws Exception {
		setPojoWithData();
		return 0; //StudentsImpl.update(pjo);

	}

	@Override
	protected void setPojoWithData() throws Exception {
		pjo.setCode(custNo);
		pjo.setFullName(nama);
		pjo.setAddress(alamat);
	/*	pjo.setPhone(Util.nullToString(cmp.getfTglLahir().getText()));
		pjo.setEmail(Util.nullToString(cmp.getfEmail().getText()));
		pjo.setFatherMother(Util.nullToString(cmp.getfPhone().getText()));


		if (cmp.getfLaki().getSelection()){
			pjo.setGender("L");
		}else{
			pjo.setGender("P");
		}
		
		pjo.setBirthDate(cmp.getfTglLahir().getSelection());
		pjo.setBirthPlace(cmp.getfBirthPlace().getText());
		pjo.setAddress(cmp.getfAddress().getText());
		
		pjo.setFatherMother(cmp.getfParent().getText());
		pjo.setEducation(cmp.getCmbPendidikan().getText());
		
		pjo.setEmail(cmp.getfEmail().getText());
		pjo.setPhone(cmp.getfPhone().getText());
		pjo.setParentJob(cmp.getfParentJob().getText());
		pjo.setParentPhone(cmp.getfParentPhone().getText());
		pjo.setOperator(cmp.getfOperator().getText());
        
		pjo.setRegDate(cmp.getfTanggalDaftar().getSelection());
		pjo.setCourseLevel(cmp.getCmbLevel().getText());
        
		pjo.setSession1(cmp.getCmbSession().getText());
        
		pjo.setRegistrationFee(cmp.getfBiayaDaftar().getValue());
		pjo.setMonthlyFee(cmp.getfBiayaBulanan().getValue());
		pjo.setPeriode(cmp.getCmbPeriode().getText());
		pjo.setPeriodeDate(cmp.getfTanggalPeriode().getText());
		pjo.setMonday(cmp.getfSenin().getSelection());
		pjo.setTuesday(cmp.getfSelasa().getSelection());
		pjo.setWednesday(cmp.getfRabu().getSelection());
		pjo.setTrusday(cmp.getfKamis().getSelection());
		pjo.setFriday(cmp.getfJumat().getSelection());
		pjo.setSaturday(cmp.getfSabtu().getSelection());
		pjo.setSunday(cmp.getfMinggu().getSelection());
		pjo.setStartDate(cmp.getfStartCourse().getSelection());
		UtilPojo.setDateAndUser(pjo);*/
	}

	@Override
	protected void disabledOtherButton(boolean enable) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void getPanelContent(Composite grpData) {
		// TODO Auto-generated method stub
		
	}

}
